package org.jseda.thread;

/**
 * Basic thread utility methods.
 * @author "John McNair" <john@mcnair.org>
 */
public class ThreadUtil
{
  /**
   * Wait for the specified object for the given amount of time.  This method
   * eats the InterruptedException if any.
   *
   * @param object the Object on which to call wait();
   * @param waitTime the amount of time in milliseconds to wait
   */
  public static void wait(Object object, long waitTime)
  {
    try
    {
      synchronized(object)
      {
        object.wait(waitTime);
      }
    }
    catch (InterruptedException e)
    {
      // Eat this exception
    }
  }

  /**
   * Sleep for the specified object for the given amount of time.  This method
   * eats the InterruptedException if any.
   *
   * @param object the Object on which to call wait();
   * @param sleepTime the amount of time in milliseconds to sleep
   */
  public static void sleep(long sleepTime)
  {
    try
    {
      Thread.sleep(sleepTime);
    }
    catch (InterruptedException e)
    {
      // Eat this exception
    }
  }

  /**
   * Invoke notifyAll() on the given object and eat the InterruptedException
   * if any.
   * @param object the Object on which to call notifyAll()
   */
  public static void notifyAll(Object object)
  {
    synchronized(object)
    {
      object.notifyAll();
    }
  }
}
